{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "76aa2e9e",
   "metadata": {
    "papermill": {
     "duration": 0.002973,
     "end_time": "2022-06-02T09:42:45.211747",
     "exception": false,
     "start_time": "2022-06-02T09:42:45.208774",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "# python网络爬虫应用实战（第20期）第2课书面作业\n",
    "学号：115799\n",
    "\n",
    "**作业内容：**  \n",
    "1. 安装Python环境并截图  \n",
    "2. 尝试安装request、BeautifulSoup 库并截图  \n",
    "3. 编写一个简单的程序，实现以下功能\n",
    "\n",
    "输入：完整网址  \n",
    "输出：域名部分  \n",
    "比如说，输入：http://www.baidu.com/s?wd=%E7%88%AC%E8%99%AB&rsv_spt=1&rsv_iqid=0xea65e60300007d2a&issp=1&f=8&rsv_bp=0&rsv_idx=2&ie=utf-8&tn=02049043_62_pg&rsv_enter=1&rsv_sug3=5&rsv_sug1=3&rsv_sug7=100&rsv_sug2=0&inputT=1169&rsv_sug4=2873&rsv_sug=1  \n",
    "输出：www.baidu.com"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f4985bef",
   "metadata": {
    "papermill": {
     "duration": 0.001755,
     "end_time": "2022-06-02T09:42:45.215727",
     "exception": false,
     "start_time": "2022-06-02T09:42:45.213972",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "## 第1题\n",
    "安装Python环境并截图。  "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8052a1ca",
   "metadata": {
    "papermill": {
     "duration": 0.001683,
     "end_time": "2022-06-02T09:42:45.219420",
     "exception": false,
     "start_time": "2022-06-02T09:42:45.217737",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "## 第2题\n",
    "深度安装request、BeautifulSoup库并截图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "9fffe40a",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-06-02T09:42:45.226213Z",
     "iopub.status.busy": "2022-06-02T09:42:45.225261Z",
     "iopub.status.idle": "2022-06-02T09:42:45.436281Z",
     "shell.execute_reply": "2022-06-02T09:42:45.435499Z"
    },
    "papermill": {
     "duration": 0.217052,
     "end_time": "2022-06-02T09:42:45.438467",
     "exception": false,
     "start_time": "2022-06-02T09:42:45.221415",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2.27.1\n",
      "<class 'bs4.BeautifulSoup'>\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "from bs4 import BeautifulSoup\n",
    "\n",
    "print(requests.__version__)\n",
    "print(BeautifulSoup)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "04eef829",
   "metadata": {
    "papermill": {
     "duration": 0.001881,
     "end_time": "2022-06-02T09:42:45.442606",
     "exception": false,
     "start_time": "2022-06-02T09:42:45.440725",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "## 第3题"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "a958dd28",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-06-02T09:42:45.451669Z",
     "iopub.status.busy": "2022-06-02T09:42:45.450402Z",
     "iopub.status.idle": "2022-06-02T09:42:45.456902Z",
     "shell.execute_reply": "2022-06-02T09:42:45.455733Z"
    },
    "papermill": {
     "duration": 0.014184,
     "end_time": "2022-06-02T09:42:45.458910",
     "exception": false,
     "start_time": "2022-06-02T09:42:45.444726",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "www.baidu.com\n"
     ]
    }
   ],
   "source": [
    "from urllib import parse\n",
    "\n",
    "# 输入URL字符串\n",
    "url = 'http://www.baidu.com/s?wd=%E7%88%AC%E8%99%AB&rsv_spt=1&rsv_iqid=0xea65e60300‘\\\n",
    "’007d2a&issp=1&f=8&rsv_bp=0&rsv_idx=2&ie=utf-8&tn=02049043_62_pg&rsv_enter=1&rsv_sug3'\\\n",
    "'=5&rsv_sug1=3&rsv_sug7=100&rsv_sug2=0&inputT=1169&rsv_sug4=2873&rsv_sug=1'\n",
    "\n",
    "result = parse.urlparse(url)\n",
    "print(result.hostname)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "461b8aae",
   "metadata": {
    "papermill": {
     "duration": 0.00215,
     "end_time": "2022-06-02T09:42:45.463315",
     "exception": false,
     "start_time": "2022-06-02T09:42:45.461165",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  },
  "papermill": {
   "default_parameters": {},
   "duration": 9.864116,
   "end_time": "2022-06-02T09:42:46.086254",
   "environment_variables": {},
   "exception": null,
   "input_path": "__notebook__.ipynb",
   "output_path": "__notebook__.ipynb",
   "parameters": {},
   "start_time": "2022-06-02T09:42:36.222138",
   "version": "2.3.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
